#include <stdio.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>

int main()
{
    int fd;
    struct stat st;
    void *p = NULL;

    fd = open("abc.txt", O_RDONLY);
    if(fd < 0){
        printf("open file failed\n");
        return -1;
    }

    fstat(fd, &st);

    p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
    if(p == MAP_FAILED)
        return -2;

    printf("map file content: %s\n", (char *)p);

    munmap(p, st.st_size);
    return 0;
}